var deviceInfo = function() {
    document.getElementById("platform").innerHTML = device.platform;
    document.getElementById("version").innerHTML = device.version;
    document.getElementById("uuid").innerHTML = device.uuid;
    document.getElementById("name").innerHTML = device.name;
    document.getElementById("width").innerHTML = screen.width;
    document.getElementById("height").innerHTML = screen.height;
    document.getElementById("colorDepth").innerHTML = screen.colorDepth;
};



function roundNumber(num) {
    var dec = 3;
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}

var accelerationWatch = null;



var preventBehavior = function(e) {
    e.preventDefault();
};



function fail(msg) {
    alert(msg);
}




function contacts_success(contacts) {
    /*alert(contacts.length
            + ' contacts returned.'
            + (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted)
                    : ''));*/
    var i = 0;
   	for(i = 0; i < contacts.length; i = i + 1) {
   		document.getElementById("contactlist").innerHTML += i.toString().concat(": ");
    	document.getElementById("contactlist").innerHTML += contacts[i].name.formatted.concat( "<br/>");
    }
}

function get_contacts() {
    var obj = new ContactFindOptions();
    obj.filter = "";
    obj.multiple = true;
    navigator.contacts.find(
            [ "name" , "phoneNumbers" , "emails" , "urls" ], contacts_success,
            fail, obj);
}



function init() {
    // the next line makes it impossible to see Contacts on the HTC Evo since it
    // doesn't have a scroll button
    // document.addEventListener("touchmove", preventBehavior, false);
    document.addEventListener("deviceready", deviceInfo, true);
}
